﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;


namespace BigNumber.NUnitTests
{
  /// <summary>
  /// This class will sanity test StdBigNumber VS the system Int64 to make sure 
  /// that all the basic functionality works for a random input.
  /// These tests are not exhaustive!
  /// </summary>
  [TestFixture]
  public class NUnitSanityTests
  {
    
    [Test]
    public void TestStdBigNumber_Creatoin()
    {
      Int64BigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber = TestsHelper.GenerateRandomNumber(18, 1);
        number1 = new Int64BigNumber(tempNumber);
        number2 = new StdBigNumber(tempNumber);
        Assert.IsTrue(number1.ToString() == number2.ToString());
      }
    }

    [Test]
    public void TestStdBigNumber_Sum()
    {
      Int64BigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber1 = TestsHelper.GenerateRandomNumber(18, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(18, 1);
        number1 = (new Int64BigNumber(tempNumber1)) + (new Int64BigNumber(tempNumber2));
        number2 = (new StdBigNumber(tempNumber1)) + (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(),String.Format("Int64 was {0} and StdBigNumber was {1}",number1.ToString(),number2.ToString()));
      }
    }

    [Test]
    public void TestStdBigNumber_Sub()
    {
      Int64BigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber1 = TestsHelper.GenerateRandomNumber(18, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(18, 1);
        number1 = (new Int64BigNumber(tempNumber1)) - (new Int64BigNumber(tempNumber2));
        number2 = (new StdBigNumber(tempNumber1)) - (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("Int64 was {0} and StdBigNumber was {1}", number1.ToString(), number2.ToString()));
      }
    }

    [Test]
    public void TestStdBigNumber_Mul()
    {
      Int64BigNumber number1;
      StdBigNumber number2;
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        string tempNumber1 = TestsHelper.GenerateRandomNumber(9, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(9, 1);
        number1 = (new Int64BigNumber(tempNumber1)) * (new Int64BigNumber(tempNumber2));
        number2 = (new StdBigNumber(tempNumber1)) * (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("Int64 was {0} and StdBigNumber was {1}", number1.ToString(), number2.ToString()));
      }
    }

    [Test]
    public void TestStdBigNumber_Div()
    {
      Int64BigNumber number1;
      StdBigNumber number2;
      Random rnd = new Random();
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        int divisorLength = rnd.Next(2, 9);
        string tempNumber1 = TestsHelper.GenerateRandomNumber(18, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(divisorLength, 0);
        number1 = (new Int64BigNumber(tempNumber1)) / (new Int64BigNumber(tempNumber2));
        number2 = (new StdBigNumber(tempNumber1)) / (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("Int64 was {0} and StdBigNumber was {1}", number1.ToString(), number2.ToString()));
      }
    }

    [Test]
    public void TestStdBigNumber_Mod()
    {
      Int64BigNumber number1;
      StdBigNumber number2;
      Random rnd = new Random();
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        int divisorLength = rnd.Next(2, 9);
        string tempNumber1 = TestsHelper.GenerateRandomNumber(18, 1);
        string tempNumber2 = TestsHelper.GenerateRandomNumber(divisorLength, 0);
        number1 = (new Int64BigNumber(tempNumber1)) % (new Int64BigNumber(tempNumber2));
        number2 = (new StdBigNumber(tempNumber1)) % (new StdBigNumber(tempNumber2));
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("Int64 was {0} and StdBigNumber was {1}", number1.ToString(), number2.ToString()));
      }
    }

    [Test]
    public void TestStdBigNumber_IsOneOrZero()
    {
      StdBigNumber o = 1;
      StdBigNumber z = 0;
      Assert.IsFalse(o.IsZero);
      Assert.IsFalse(z.IsOne);
      Assert.IsTrue(o.IsOne);
      Assert.IsTrue(z.IsZero);
    }

    [Test]
    public void TestStdBigNumber_Negate()
    {
      Int64BigNumber number1;
      StdBigNumber number2;
      Random rnd = new Random();
      for (int i = 0; i < TestsHelper.TEST_COUNT; i++)
      {
        int divisorLength = rnd.Next(2, 9);
        string tempNumber1 = TestsHelper.GenerateRandomNumber(18, 1);
        number1 = new Int64BigNumber(tempNumber1);
        number1.Negate();
        number2 = new StdBigNumber(tempNumber1);
        number2.Negate();
        Assert.IsTrue(number1.ToString() == number2.ToString(), String.Format("Int64 was {0} and StdBigNumber was {1}", number1.ToString(), number2.ToString()));
      }
    }

  }
}
